{% extends "blog/index.html" %}

{% block title %}
{{ article.title }} - 残阳似血的博客
{% endblock %}

{% block css %}
<link type="text/css" rel="stylesheet" href="/static/blog/css/SyntaxHighlighter/shCoreDefault.css"><link> 
<link type="text/css" rel="stylesheet" href="/static/blog/css/jqueryui/jquery-ui-1.8.4.custom.css"><link>
<link rel="stylesheet" type="text/css" href="/static/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
{% endblock %}

{% block js %}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js"></script> 
<script src="/static/blog/js/jquery.form.js"></script> 
<script type="text/javascript" src="/static/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="/static/fancybox/jquery.fancybox-1.3.4.pack.js"></script>

<script language="JavaScript" src="/static/blog/js/SyntaxHighlighter/shCore.js"></script> 
<script language="JavaScript" src="/static/blog/js/SyntaxHighlighter/shAutoloader.js"></script> 
<script language="JavaScript"> 
	$(document).ready(function(){
		SyntaxHighlighter.autoloader(
		  'cpp c                  /static/blog/js/SyntaxHighlighter/shBrushCpp.js',
		  'c# c-sharp csharp      /static/blog/js/SyntaxHighlighter/shBrushCSharp.js',
		  'css                    /static/blog/js/SyntaxHighlighter/shBrushCss.js',
		  'java                   /static/blog/js/SyntaxHighlighter/shBrushJava.js',
		  'js jscript javascript  /static/blog/js/SyntaxHighlighter/shBrushJScript.js',
		  'text plain             /static/blog/js/SyntaxHighlighter/shBrushPlain.js',
		  'py python              /static/blog/js/SyntaxHighlighter/shBrushPython.js',
		  'sql                    /static/blog/js/SyntaxHighlighter/shBrushSql.js',
		  'xml xhtml xslt html    /static/blog/js/SyntaxHighlighter/shBrushXml.js',
		  'go                     /static/blog/js/SyntaxHighlighter/shBrushGo.js'
		);
		SyntaxHighlighter.all();
	});
	
	var wzt = encodeURIComponent(document.title);
	var wztb = escape(document.title);
	var wzu = encodeURIComponent(location.href);
	var wzub = escape(location.href);
	var title = document.title;
	var sc = location.href;
	
	function getLink(s){
		switch(s){
			case "renren":
				return "http://share.renren.com/share/buttonshare.do?link="+wzu+"&title="+wzt;
			case "kaixin001":
				return "http://www.kaixin001.com/repaste/share.php?rurl="+wzu+"&rcontent="+wzu+"&rtitle="+wzt;
			case "qzone":
			    return "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+wzu+"&title="+wzt;
			case "douban":
			    return "http://www.douban.com/recommend/?url="+wzu+"&title="+wzt;
			case "sina-weibo":
			    return "http://v.t.sina.com.cn/share/share.php?appkey=2233047537&url="+wzu+"&title="+wzt;
			case "qq-weibo":
			    return "http://v.t.qq.com/share/share.php?title="+wzt+'&url='+wzu;
			case "sohu-weibo":
			    return "http://t.sohu.com/third/post.jsp?&url="+wzu+"&title="+wztb;
			case "163-weibo":
			    return "http://t.163.com/article/user/checkLogin.do?source=残阳似血的博客&link="+wzu+"&info="+wzt;
		}
	}
	
	function setDialogContent(s, success, callback){
		var s2;
		if(success){
			s2 = "<span class='ui-icon ui-icon-circle-check' style='float:left; margin:0 7px 50px 0;'></span>";
		}
		else{
			s2 = "<span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 50px 0;'></span>";
		}
		$("#dialog p").html(s2+s);
		
		if(callback != void 0){
			callback();
		}
	}
	
	var regExp = /[\u4e00-\u9fa5]/g;
	function enableAjaxForm(){
		$("#commentform, #replycommentform").ajaxForm({
			beforeSubmit:function(arr, $form, options){
				for(a in arr){
					var obj = arr[a];
					var name = obj.name;
					var value = obj.value;
					if((name=='username'||name=='email_address')&&(value==''||typeof value==undefined)){
						$('#replycommentformwrapper').dialog('close');
						setDialogContent("评论失败，昵称或邮箱地址没有填写！", false);
						$('#dialog').dialog('open');
						return false;
					}
					if(name=='content'&&value.match(regExp)==null) {
						$('#replycommentformwrapper').dialog('close');
						setDialogContent("评论失败，评论中必须包含中文！", false);
						$('#dialog').dialog('open');
						return false;
					}
				}
			},
            success:function(responseText,statusText){
                if(responseText == "0"){
					setDialogContent("评论失败，请确保全部信息填写正确！", false);
				}
				else if(responseText == "1"){
					setDialogContent("评论成功！", true);
					$("textarea#id_content").val('');
					$("#comment").load("/comment/{{ article.slug }}/");
				}
				$('#replycommentformwrapper').dialog('close');
				$('#dialog').dialog('open');
            }
        });
		$("#emailform").ajaxForm({
			beforeSubmit:function(arr, $form, options){
				for(a in arr){
					var obj = arr[a];
					var name = obj.name;
					var value = obj.value;
					if((name=='name'||name=='email'||name=='toemail')&&(value==''||typeof value==undefined)){				
						$('#emailformwrapper').dialog('close');
						setDialogContent("邮件发送失败，昵称或邮箱地址没有填写！", false);
						$('#dialog').dialog('open');
						return false;
					}
				}
			},
            success:function(responseText,statusText){
                if(responseText == "0"){
					setDialogContent("邮件发送失败！", false);
				}
				else if(responseText == "1"){
					setDialogContent("邮件发送成功！", true);
				}
				$('#emailformwrapper').dialog('close');
				$('#dialog').dialog('open');
            }
        });
	}
    
	$(function() {
		$('#dialog').dialog({
			autoOpen: false,
			show: 'blind',
			hide: 'explode',
			modal: true,
			buttons: {
				'确认': function() {
					$(this).dialog('close');
				}
			}
		});
		
		$('#replycommentformwrapper').dialog({
			autoOpen: false,
			modal: true,
			width: 555
		});
		
		$('#emailformwrapper').dialog({
			autoOpen: false,
			modal: true,
			width: 600
		});
		
		enableAjaxForm();
		
		$("a.comment-reply-link").live('click', function(){
			$('#replycommentformwrapper').dialog({'title': $(this).attr('name')})
			$("#replycommentform #id_reply_to_comment").val($(this).attr('href').substring(9));
			$('#replycommentformwrapper').dialog('open');
			return false;
		})
		
		$('.send-email').click(function(){
			$('#emailformwrapper').dialog('open');
			return false;
		})
		
		$("input#logout").click(function(){
			location.href = "/logout/";
			return false;
		})
		$("span#expand").click(function(){
			$("input#logout").toggle(200);
			$("span#expand span.ui-icon").toggleClass("ui-icon-triangle-1-e").toggleClass("ui-icon-triangle-1-w");
		})
		
		$('body').ajaxStart(function(){
			$(this).addClass('overlay')
		});
		$('body').ajaxComplete(function(){
			$(this).removeClass('overlay')
		});
		
		$("div.post div.right p img").each(function(i){
			if($(this).parent("a").size() == 0){
				imgSrc = $(this).attr("src");
				$(this).wrap("<a href='"+imgSrc+"'></a>");
				$(this).parent().fancybox();
			}
		});
		
		$("div#footer-bottom p.bottom-right a:last").click(function(){
			targetOffset = $("body").offset().top;
			$('html,body').stop().animate({scrollTop: targetOffset}, 500);
			return false;
		});
	});
</script>
{% endblock %}

{% block content %}
<div class="post">

 	<div class="right">

       <h2><a href="{{ article.get_absolute_url }}">{{ article.title }}</a>&nbsp;<g:plusone href="http://qinxuye.me{{ article.get_absolute_url }}"></g:plusone></h2>

       <p class="post-info">文章在分类 <a href="{{ article.category.get_absolute_url }}">{{ article.category }}</a>下</p>

       {{ article.content|safe }}

       <div class="share-box clear" >

				<h4>分享到</h4>

          <ul>
          	<li><a title="RSS" href="{{ article_rss }}" rel="nofollow">
						<img alt="RSS" title="RSS" src="/static/blog/images/sns/32-rss.png" /></a>
					</li>
			<li><a title="分享到新浪微博" href="#" target="_blank" rel="nofollow" onclick="$(this).attr('href',getLink('sina-weibo'));">
						<img alt="分享到新浪微博" title="分享到新浪微博" src="/static/blog/images/sns/32-weibo.png" /></a>
					</li>
					<li><a title="分享到QQ微博" href="#" target="_blank" rel="nofollow" onclick="$(this).attr('href',getLink('qq-weibo'));">
						<img alt="分享到QQ微博" title="分享到QQ微博" src="/static/blog/images/sns/32-qqweibo.png" /></a>
					</li>
             <li><a title="分享到人人网" href="#" target="_blank" rel="nofollow" onclick="$(this).attr('href',getLink('renren'));">
						<img alt="分享到人人网" title="分享到人人网" src="/static/blog/images/sns/32-renren.png" /></a>
					</li>
					<li><a title="分享到开心网" href="#" target="_blank" rel="nofollow" onclick="$(this).attr('href',getLink('kaixin001'));">
						<img alt="分享到开心网" title="分享到开心网" src="/static/blog/images/sns/32-kaixin001.png" /></a>
					</li>
             <li><a title="分享到QQ空间" href="#" target="_blank" rel="nofollow" onclick="$(this).attr('href',getLink('qzone'));">
						<img alt="分享到QQ空间" title="分享到QQ空间" src="/static/blog/images/sns/32-qzone.png" /></a>
					</li>
					<li><a title="分享到豆瓣网" href="#" target="_blank" rel="nofollow" onclick="$(this).attr('href',getLink('douban'));">
						<img alt="分享到豆瓣网" title="分享到豆瓣网" src="/static/blog/images/sns/32-douban.png" /></a>
					</li>
             <li><a title="分享到搜狐微博" href="#" target="_blank" rel="nofollow" onclick="$(this).attr('href',getLink('sohu-weibo'));">
						<img alt="分享到搜狐微博" title="分享到搜狐微博" src="/static/blog/images/sns/32-sohuweibo.png" /></a>
					</li>
					<li><a title="分享到网易微博" href="#" target="_blank" rel="nofollow" onclick="$(this).attr('href',getLink('163-weibo'));">
						<img alt="分享到网易微博" title="分享到网易微博" src="/static/blog/images/sns/32-163weibo.png" /></a>
					</li>
					<li><a class="send-email" title="E-mail this story to a friend!" href="#" rel="nofollow">
						<img alt="E-mail this story to a friend!" title="E-mail this story to a friend!" src="/static/blog/images/sns/32-mail.png" /></a>
					</li>
          </ul>

			</div>

    </div>

    <div class="left">

    	<p class="dateinfo">{{ article.modified|date:"M" }}<span>{{ article.modified|date:"j" }}</span></p>

       <div class="post-meta">
       	<h4>文章信息</h4>
          <ul>
          	<li class="user"><a href="#">{{ article.author }}</a></li>
            <li class="time"><a href="#">{{ article.modified|date:"P" }}</a></li>
            <li class="comment"><a id="comment-link" href="#comment">{{ n_comment }}个评论</a></li>
            <li class="permalink"><a href="{{ article.get_absolute_url }}">持久链接</a></li>
		  </ul>
	   </div>

       {% if tags %}
       <div class="post-meta">
       	<h4>标签</h4>
			 <ul class="tags">
			 	{% for tag in tags %}
	         	<li><a href="{{ tag.get_absolute_url }}" rel="tag">{{ tag.name }}</a></li>
	            {% endfor %}
	         </ul>
       </div>
       {% endif %}
    </div>

	</div>


 <div id="comment" class="post-bottom-section"{% if n_comment == 0 %} style="border:0px; margin:0; padding:0;"{% endif %}>
	{% if n_comment > 0 %}
		<h4>目前有{{ n_comment }}个评论</h4>
	
    <div class="right">
		
    	<ol class="commentlist">
    		{% load mptt_tags %}
			{% recursetree nodes %}
		        <li id="comment-{{ node.id }}" class="{{ node.classname }}">
		            <div class="comment-info">
						<img alt="" src="{% if node.avatar %}{{ node.avatar }}{% else %}/static/blog/images/gravatar.jpg{% endif %}" class="avatar" height="40" width="40" />
						<cite>
							<a href="{% if node.site %}{{ node.site }}{% else %}#comment-{{ node.id }}{% endif %}"{% if node.weibo_name %} wb_screen_name="{{ node.weibo_name }}"{% endif %}>{{ node.username }}</a> 说： <br />
							<span class="comment-data"><a href="#comment-{{ node.id }}" title="">{{ node.post_date|date:"Y年 bj日 P" }}</a></span>
						</cite>
					</div>
					<div class="comment-text">
						<p>{{ node.content|safe }}</p>
						<div class="reply">
							<a rel="nofollow" class="comment-reply-link" href="#comment-{{ node.id }}" name="回复{{ node.username }}：">回复</a>
 						</div>
					</div>

		            {% if not node.is_leaf_node %}
		                <ul class="children">
		                    {{ children }}
		                </ul>
		            {% endif %}
		        </li>
		    {% endrecursetree %}

		</ol>
			
    </div>
	{% endif %}
 </div>

 <div class="post-bottom-section">

		<h4>给作者留言</h4>

    <div class="right">

    	<form action="{% url program-comment %}" method="post" id="commentform">
		{{ form.article }}
		{{ form.reply_to_comment }}
		{{ form.avatar }}
       	<p>
			 		<label for="username">昵称 (必填){{ form.username.errors }}</label><br />
					{{ form.username }}
				</p>
          <p>
				 	<label for="email_address">电子邮箱 (会为你保密) (必填)</label><br />
					{{ form.email_address }}
				</p>
          <p>
					<label for="site">网址</label><br />
					{{ form.site }}
				</p>
          <p>
					<label for="content">您的留言</label><br />
					{{ form.content }}
				</p>
          <p class="no-border">				
		            <input class="button" type="submit" value="提交评论" />	
					{% if weibo_log %}
					<input type="checkbox" id="sendWeibo" name="sendWeibo" value ="true" checked="checked">同时发送至微博
					<span id="logout-wrapper">
					<input id="logout" class="button" type="submit" value="退出新浪微博" />
					<span id="expand" class="ui-state-default ui-corner-all" title="展开"><span class="ui-icon ui-icon-triangle-1-e"></span></span>
					</span>
					{% endif %}
				</p>

       </form>

    </div>

 </div>
 
<!-- hidden-area -->
<div id="dialog" title="需要提醒您："> 
	<p></p> 
</div>

<div id='replycommentformwrapper' title="">
	<form action="{% url program-comment %}" method="post" id="replycommentform">
	{{ form.article }}
	{{ form.reply_to_comment }}
	{{ form.avatar }}
		<p>
		 		<label for="username">昵称 (必填){{ form.username.errors }}</label><br />
				{{ form.username }}
			</p>
	  <p>
			 	<label for="email_address">电子邮箱 (会为你保密) (必填)</label><br />
				{{ form.email_address }}
			</p>
	  <p>
				<label for="site">网址</label><br />
				{{ form.site }}
			</p>
	  <p>
				<label for="cotent">您的留言</label><br />
				{{ form.content }}
			</p>
	  <p class="no-border">
				<input class="button" type="submit" value="提交评论" />
			</p>
	
	</form>
</div>

<div id='emailformwrapper' title="把文章Email给朋友">
	<form action="{% url program-email %}" method="post" id="emailform">
		<p>
		 		<label for="name">你的昵称（必填）</label><br />
				<input id="name" name="name" type="text" tabindex="1" />
			</p>
	  <p>
			 	<label for="email">你的电子邮箱（必填）</label><br />
				<input id="email" name="email" type="text" tabindex="2" />
			</p>
	  <p>
				<label for="toemail">要发送的电子邮箱（必填，多个邮箱用逗号隔开）</label><br />
				<input id="toemail" name="toemail" type="text" tabindex="3" />
			</p>
	  <p>
				<label for="message">您的留言</label><br />
				<textarea id="message" name="message" rows="10" cols="20" tabindex="4">我在残阳似血的博客上看到一篇很赞的文章，《{{ article.title }}》，地址：http://qinxuye.me{{ article.get_absolute_url }}</textarea>
			</p>
	  <p class="no-border">
				<input class="button" type="submit" value="发送Email" />
			</p>
	
	</form>
</div>
<!-- /hidden-area -->

{% endblock %}

{% block footerjs %}
<script type="text/javascript">
  window.___gcfg = {lang: 'zh-CN'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
{% endblock %}
